/**
 * 
 */
package cc.dogtailflower.framework.resultsetmapper;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cc
 *
 */
public class ResultSetMapperNoClassImpl<T> implements ResultSetMapper<T>{

	@SuppressWarnings("unchecked")
	@Override
	public List<T> resultSetToObject(ResultSet rs, Class<?> outputClass) throws SQLException {

		List<T> outputList = new ArrayList<T>();
		try{
			if(rs != null){
					ResultSetMetaData rsmd = rs.getMetaData();
					while(rs.next()){
						Map<String,Object> map = new HashMap<String,Object>();
						for(int iterator =0;iterator < rsmd.getColumnCount();iterator++){
							String columnName = rsmd.getColumnName(iterator+1);
							Object columnValue = rs.getObject(iterator+1);
							map.put(columnName, columnValue);
						}
						outputList.add((T)map);
					}
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return outputList;
	}

}
